#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
		for(int i=0;i<t;i++){
			int x,y;
			char f;
			scanf("%x%c%x",&x,&f,&y);
			if(f=='+') printf("%o\n",x+y);
			else printf("%o\n",x-y);
		}
	
}
